#include<bits/stdc++.h>

using namespace std;
int a[50][50] = {
        {7, 0, 0, 0, 0},
        {3, 8, 0, 0, 0},
        {8, 1, 0, 0, 0},
        {2, 7, 4, 4, 0},
        {4, 5, 2, 6, 5},
};
int n = 50;
int dp[50][50] = {0};//dp[i][j]

int main() {
    for (int i = 0; i < n; i++) {
        dp[n - 1][i] = a[n - 1][i];
    }
    for (int i = n - 2; i >= 0; i--) {
        for (int j = 0; j <= i; j++) {
            dp[i][j] = a[i][j] + max(dp[i + 1][j], dp[i + 1][j + 1]);
        }
    }
    cout << dp[0][0];
}
